<template>
	<view class="app">
		<view class="price-box">
			<text>支付金额</text>
			<text class="price">38.88</text>
		</view>

		<view class="pay-type-list">
			<view class="type-item" v-if="show_yue" @click="changePayType('yu_e')">
				<text class="icon yticon icon-erjiye-yucunkuan"></text>
				<view class="con">
					<text class="tit">积分支付</text>
					<text>可用积分 ¥198.5</text>
				</view>
				<label class="radio">
					<radio value="" color="#20cbd4" :checked="payType == 'yu_e'" />
					</radio>
				</label>
			</view>
			<view class="type-item b-b" @click="changePayType('weixin')">
				<text class="rmb-circle-fill icon yticon icon-weixinzhifu"></text>
				<view class="con">
					<text class="tit">微信支付</text>
					<text>推荐使用微信支付</text>
				</view>
				<label class="radio">
					<radio value="" color="#20cbd4" :checked="payType == 'weixin'" />
					</radio>
				</label>
			</view>
			<!--  #ifndef MP-WEIXIN -->
			<view class="type-item b-b" @click="changePayType('zhifubao')">
				<text class="icon yticon icon-alipay"></text>
				<view class="con">
					<text class="tit">支付宝支付</text>
				</view>
				<label class="radio">
					<radio value="" color="#20cbd4" :checked="payType == 'zhifubao'" />
					</radio>
				</label>
			</view>
			<!-- #endif -->
		</view>
		
		<text class="mix-btn" @click="confirm">确认支付</text>
		<u-modal width="80%" v-model="payPwdShow" :show-title="true"
		confirm-color="#20cbd4" :show-cancel-button="true" @confirm="payYE">
			<view class="modelContent">
				<view class="accountData">
					<text>交易密码：</text>
					<u-input v-model="payPassword" type="password"
						placeholder="请输入交易密码"/>
				</view>
			</view>
		</u-modal>
		<login-model ref="loginModel"></login-model>
		<u-toast ref="uToast" />
		<view v-html="alipayForm"></view>
	</view>
	
</template>

<script>
	import {orderCartH5,orderCartZfb,hjWxCarPay,hjVxPay,payZfb,buyNow,pay,orderCart,carPay,isBuyNow,isOrderCart,wxminiGetOpenid,payGzh,wxPay,wxCarPay,orderCartGzh,payH5} from "@/common/api.js";
	import loginModel from "@/components/public/loginModel.vue";
	export default {
		components: {
			loginModel
		},
		data() {
			return {
				payType: 'yu_e',
				show_yue: 1,
				alipayForm:"",
				payPwdShow:false,
				payPassword:"",
				order_id:0,
				orderInfo: {},
			};
		},
		computed: {
		
		},
		onLoad(options) {
			var order_id = options.order_id;
			this.order_id = order_id;
			this.findOrder();
		},

		methods: {
			//
			findOrder(){
				var _this = this;
				var order_id = this.order_id;
				if(order_id==0){
					_this.$refs.uToast.show({title: '参数不存在',})
				}
			},
			//选择支付方式
			changePayType(type) {
				this.payType = type;
				
			},
			//确认支付
			confirm: async function() {
				if(this.payType=='yu_e'){
					if(this.payPassword==""){
						this.payPwdShow=true;
					}else{
						gotopay(this,{pay_type:'yu_e',order_id:this.order_id,pay_pwd:this.payPassword});
						
					}
					return;
				}else{
					this.settle()
					return;
				}
				uni.redirectTo({
					url: '/pages/money/paySuccess'
				})
			},
			settle: async function(){
				var _this = this;
				var pay_type = 'yu_e';
				// #ifdef MP-WEIXIN
				if(uni.getStorageSync("openid")==""){
					uni.getSetting({
						success: function (a) {
							uni.getUserProfile({
								desc:'Wexin',  
								success: function (b) {
									 uni.login({
									    success (res) {
											uni.hideLoading();
									        if (res.code) {
												wxminiGetOpenid(_this,{code:res.code})
									        } else {
												_this.$refs.uToast.show({title: '授权获取失败',})
									        }
									    }
									})
								}
							});
						}
					});
				}
				if(uni.getStorageSync("openid")!="" && uni.getStorageSync("openid")!="undefined"){
					pay_type = 'wx_mini';
				}
				// #endif
				
				// #ifdef APP-PLUS
				if(_this.payType=='zhifubao'){
					pay_type = 'ali_app';
				}else{
					pay_type = 'wx_app';
				}
				// #endif
				
				// #ifdef H5
					let ua = window.navigator.userAgent.toLowerCase()
					if (ua.match(/MicroMessenger/i) == 'micromessenger') {
						if(_this.payType=='zhifubao'){
							uni.hideLoading();
							_this.$refs.uToast.show({title: '微信浏览器无法用支付宝支付',})
							return;
						}else{
							pay_type = 'wx_chat';
						}
					}else{
						if(_this.payType=='zhifubao'){
							pay_type = 'ali_h5';
							if(this.params.type == 0){
								//类型为0时说明从商品详情来
								payZfb(this,{pay_type:'ali_h5',goods_id:this.params.goods_id,goods_sku_id:this.params.goods_sku_id,goods_num:this.params.goods_num,address_id:this.order.address.id,remark:this.remark,coupon_id:this.coupon_id,be_assist_id:this.assist_id,roomid:this.roomid,zsgids:this.zsgoodskuid})
							}else{
								//从购物车来
								orderCartZfb(this,{pay_type:'ali_h5',q_id:this.params.q_id,cart_ids:this.params.cart_ids,address_id:this.order.address.id,remark:this.remark,coupon_id:this.coupon_id,be_assist_id:this.assist_id,roomid:this.roomid,zsgids:this.zsgoodskuid})
							}
						}else{
							pay_type = 'wx_h5';
							if(this.params.type == 0){
								//类型为0时说明从商品详情来
								payH5(this,{pay_type:'wx_h5',goods_id:this.params.goods_id,goods_sku_id:this.params.goods_sku_id,goods_num:this.params.goods_num,address_id:this.order.address.id,remark:this.remark,coupon_id:this.coupon_id,be_assist_id:this.assist_id,roomid:this.roomid,zsgids:this.zsgoodskuid})
							}else{
								//从购物车来
								orderCartH5(this,{pay_type:'wx_h5',q_id:this.params.q_id,cart_ids:this.params.cart_ids,address_id:this.order.address.id,remark:this.remark,coupon_id:this.coupon_id,be_assist_id:this.assist_id,roomid:this.roomid,zsgids:this.zsgoodskuid})
							}
						}
					}
				// #endif
				gotopay(this,{pay_type:pay_type,order_id:this.order_id,pay_pwd:this.payPassword});
			}
		}
	}
</script>

<style lang='scss'>
	.app {
		width: 100%;
	}
	@font-face {
		font-family: yticon;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_1078604_w4kpxh0rafi.ttf') format('truetype');
	}
	
	.yticon {
		font-family: "yticon" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}
	
	.icon-weixinzhifu:before {
		content: "\e61a";
	}
	
	.icon-comment:before {
		content: "\e64f";
	}
	
	.icon-weixin:before {
		content: "\e61f";
	}
	.icon-alipay:before {
		content: "\e636";
	}
	.icon-erjiye-yucunkuan:before {
		content: "\e623";
	}

	.price-box {
		background-color: #fff;
		height: 265upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		font-size: 28upx;
		color: #909399;

		.price{
			font-size: 50upx;
			color: #303133;
			margin-top: 12upx;
			&:before{
				content: '￥';
				font-size: 40upx;
			}
		}
	}

	.pay-type-list {
		margin-top: 20upx;
		background-color: #fff;
		padding-left: 60upx;
		
		.type-item{
			height: 120upx;
			padding: 20upx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding-right: 60upx;
			font-size: 30upx;
			position:relative;
		}
		
		.icon{
			width: 100upx;
			font-size: 52upx;
		}
		
		.icon-erjiye-yucunkuan {
			color: #fe8e2e;
		}
		.icon-weixinzhifu {
			color: #36cb59;
		}
		.icon-alipay {
			color: #01aaef;
		}
		
		.tit{
			font-size: 32upx;
			color: #303133;
			margin-bottom: 4upx;
		}
		.con{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: 24upx;
			color: #909399;
		}
	}
	.mix-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 630upx;
		height: 80upx;
		margin: 80upx auto 30upx;
		font-size: 32upx;
		color: #fff;
		background-color: #20cbd4;
		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
	.modelContent{
		padding: 40rpx;
	}
	.accountData{
		padding: 15rpx 0 15px 200rpx;position: relative;
	}
	.accountData text{position: absolute;left:0;top:15px;display: inline-block;width:190rpx;text-align: right;}
	.accountData .u-input{border-bottom:0.5rpx solid #222;}
	.accountData .u-input input{min-width:260rpx}

</style>
